package com.wy.controller;

import com.wy.utils.Constant;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2019/12/1211:00
 */
@RestController
@RequestMapping("hello")
public class HelloController {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @RequestMapping("hello")
    public Boolean sendSample(String msg){
       /* MessageProperties messageProperties = new MessageProperties();
        messageProperties.setMessageId(UUID.randomUUID().toString());
        messageProperties.setContentType("text/plain");
        messageProperties.setContentEncoding("utf-8");
        rabbitTemplate.convertAndSend(Constant.DIRECT_QUEUE,msg,messageProperties);*/

        rabbitTemplate.convertAndSend(Constant.DIRECT_QUEUE,msg);
        return true;
    }
    //work （1个生产者，多个消费者，每个消费只能被消费一次
    @RequestMapping("work")
    public Boolean sendWork(String msg){

        rabbitTemplate.convertAndSend(Constant.WORK_QUEUE,msg);
        return true;
    }

    //fanout （1个生产者，多个消费者，每个消费只能被消费一次
    @RequestMapping("fanoutExchange")
    public Boolean sendfanoutExchange(String msg){

        rabbitTemplate.convertAndSend("fanoutExchange","",msg);
        return true;
    }

    //routing （每个生产者把消息根据路由key发送到不同的队列
    @RequestMapping("routExchangeA")
    public Boolean sendRoutExchangeA(String msg){
        rabbitTemplate.convertAndSend("topicExchange","topic.keyA",msg);
        return true;
    }

    //routing （每个生产者把消息根据路由key发送到不同的队列
    @RequestMapping("routExchangeB")
    public Boolean sendRoutExchangeB(String msg){
        rabbitTemplate.convertAndSend("topicExchange","topic.keyB",msg);
        return true;
    }

    //topic （每个生产者把消息根据路由key发送到不同的队列
    @RequestMapping("routExchangeC")
    public Boolean sendRoutExchangeC(String msg){
        rabbitTemplate.convertAndSend("topicExchange","topic.keyC",msg);
        return true;
    }


}
